home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gwuada_6.zip / MENUS.C < prev    next >
C/C++ Source or Header  |  1993-09-06  |  15KB  |  604 lines

  1. /*
  2.     GWAda Development Environment for 386/486 PCs   
  3.     Copyright (C) 1993, Arthur Vargas Lopes  & Michael Bliss Feldman
  4.                         vlopes@vortex.ufrgs.br mfeldman@seas.gwu.edu
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; version 2 of the License.    
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. /*  Menus.c  */
  21.  
  22. #include <externs.h>
  23.  
  24.  
  25. /************************************************************************/
  26. /***   Inicializa o Mouse no Video                                    ***/
  27. /*                                                                      */
  28. void AVL_MOUSE_INIT()
  29. {
  30.     union REGS inreg, outreg;
  31. return;
  32.     inreg.x.ax = 0;
  33.     int86(0x33, &inreg, &outreg);
  34.     inreg.x.ax = 1;
  35.     int86(0x33, &inreg, &outreg);
  36. }
  37.  
  38. void AVL_MOUSE_ON()
  39. {
  40.     union REGS inreg, outreg;
  41. return;
  42.     inreg.x.ax = 1;
  43.     int86(0x33, &inreg, &outreg);
  44. }
  45.  
  46. void AVL_MOUSE_OFF()
  47. {
  48.     union REGS inreg, outreg;
  49. return;
  50.     inreg.x.ax = 2;
  51.     int86(0x33, &inreg, &outreg);
  52. }
  53.  
  54.  
  55. void AVL_MOUSE_SET(int x, int y)
  56. {
  57.     union REGS inreg, outreg;
  58. return;
  59.     inreg.x.ax = 4;
  60.     inreg.x.cx = x;
  61.     inreg.x.dx = y;
  62.     int86(0x33, &inreg, &outreg);
  63. }
  64.  
  65.  
  66. /************************************************************************/
  67. /***   Fornece o Status do Mouse - Posicao, Botao Precionado.            ***/
  68. /**    Botoes: 0 - esquerda                                            **/
  69. /*             1 - direita          Obs.: Definir estrutura de volta    */
  70. /*             2 - meio                   fora do programa.  xmouse     */
  71. /*                                                           ymouse     */
  72. /*    Retorna:  1 - se botao pressionado                                */
  73. /*              0 - caso contrario ou se nro. do botao for invalido     */
  74. /*                                                                      */
  75. AVL_MOUSE AVL_MOUSE_STATUS()
  76. {
  77.     union REGS inreg, outreg;
  78.     static AVL_MOUSE m;
  79.     short i;
  80. m.status = 0;
  81. return m;
  82.  
  83.     inreg.x.ax = 3;
  84.     inreg.x.bx = 0;
  85.  
  86.     int86(0x33, &inreg, &outreg);
  87.  
  88.     m.x = outreg.x.dx;
  89.     m.y = outreg.x.cx;
  90.     m.x = m.x / 8 + 1;
  91.     m.y = m.y / 8 + 1;
  92.     m.status = outreg.x.bx;
  93.  
  94.     return(m);
  95. }
  96.  
  97.  
  98.  
  99. int AVL_MOUSE_SELECT(int x1, int y1, int x2, int y2, int *row)
  100. {
  101.     AVL_MOUSE m;
  102.     m = AVL_MOUSE_STATUS();
  103. return 0;
  104.     if (m.x >= x1 && m.x <= x2 && m.y >= y1 && m.y <= y2 && m.status == 1) {
  105.         *row = m.x - x1;
  106.         avl_cur_smenu[avl_cur_menu] = *row;
  107.         AVL_SHOW_SMENU();
  108.         return 1;
  109.         }
  110.     return 0;
  111. }
  112.  
  113. int AVL_MOUSE_SELECT2(int *item)
  114. {
  115.     AVL_MOUSE m;
  116.     short k, y1, y2;
  117.     m = AVL_MOUSE_STATUS();
  118. return 0;
  119.     if (m.x == 2 && m.status == 1)  
  120.         for(k = 0; k < AVL_MENU_ITEMS; ++k)    {
  121.             y1 = avl_menu[k].c + 1;
  122.             y2 = strlen(avl_menu[k].tit) + y1 - 1;
  123.             if (m.y >= y1 && m.y <= y2 && k != avl_cur_menu)   {
  124.                 *item = avl_menu[k].tit[0];
  125.                 avl_cur_menu = k;
  126.                 AVL_SHOW_MENU();
  127.                 return 1;
  128.                 }
  129.             }
  130.     *item = avl_menu[avl_cur_menu].tit[0];
  131.     return (m.status == 1) ? 1 : 0;
  132. }
  133.  
  134.  
  135. void AVL_SHOW_SMENU()
  136. {
  137.     int i, j, rows = 0, cols = 0;
  138.     short co;
  139.     for(i = 0; *(avl_smenu[avl_cur_menu].s[i].sm) != '\0'; ++i) {
  140.         _settextposition(avl_smenu[avl_cur_menu].r+i,1);
  141.         if (avl_cur_smenu[avl_cur_menu] == i)
  142.             co = _settextcolor(avl_men_ready);
  143.         else
  144.             co = _settextcolor(avl_men_letter);
  145.         _outmem(avl_smenu[avl_cur_menu].s[i].sm,1);
  146.         if (avl_cur_smenu[avl_cur_menu] != i)
  147.             _settextcolor(avl_men_word);
  148.         _outtext(avl_smenu[avl_cur_menu].s[i].sm + 1);
  149.         }
  150. }
  151.  
  152.  
  153. int AVL_GET_SMENU_OPT()
  154. {
  155.     int ch, i, j;
  156.     short att, c1;
  157.     int rows, cols;
  158.     AVL_WIN_PTR w = NULL;
  159.     AVL_SHOW_MENU();
  160.     AVL_COMP_SMENU(&rows,&cols);
  161.     AVL_MOUSE_ON();
  162.     AVL_MOUSE_SET(2,2);
  163.     avl_no_up_corner = 1;
  164.     c1 = avl_menu[avl_cur_menu].c - 1;
  165.     ch = 78 - (c1 + cols);
  166.     if (ch < 0) c1 += ch;
  167.     if (!(rows == 0 && cols == 0))
  168.         w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
  169.     _settextcursor(0x2000);
  170.     while ( 1 ) {
  171.         if (w != NULL)
  172.             AVL_SHOW_SMENU();
  173.         _settextposition(1,1);
  174. again:
  175.         if (!kbhit())  {
  176.             if (AVL_MOUSE_SELECT(4,c1+1,rows+3,c1+cols,&i))  {
  177.                 AVL_DEL_WINDOW(w);
  178.                 if (avl_smenu[avl_cur_menu].s[i].ret_edit) {
  179.                     ch = 0;
  180.                     AVL_DEL_WINDOW(avl_env_win);
  181.                     AVL_RESTORE_ENV();
  182.                     }
  183.                 else
  184.                     ch = *(avl_smenu[avl_cur_menu].s[i].sm);
  185.                 avl_smenu[avl_cur_menu].s[i].proc();
  186. /*                if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
  187.                     AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
  188. */
  189.                 avl_no_up_corner = 0;
  190.                 AVL_MOUSE_OFF();
  191.                 return ch;
  192.                 }
  193.             goto again;
  194.             }
  195.         ch = getch();
  196.         ch = toupper(ch);
  197.         if (ch >= 'A' && ch <= 'Z')   {
  198.             if (w == NULL)  {
  199.                 AVL_ERROR("Invalid action");
  200.                 continue;
  201.                 }
  202.             for (i = 0; i < rows; ++i)
  203.                 if (*(avl_smenu[avl_cur_menu].s[i].sm) == ch) {
  204.                     avl_cur_smenu[avl_cur_menu] = i;
  205.                     AVL_DEL_WINDOW(w);
  206.                     if (avl_smenu[avl_cur_menu].s[i].ret_edit) {
  207.                         ch = 0;
  208.                         AVL_DEL_WINDOW(avl_env_win);
  209.                         AVL_RESTORE_ENV();
  210.                         }
  211.                     avl_smenu[avl_cur_menu].s[i].proc();
  212. /*                    if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
  213.                         AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
  214. */
  215.                     avl_no_up_corner = 0;
  216.                     AVL_MOUSE_OFF();
  217.                     return ch;
  218.                     }
  219.             continue;
  220.             }
  221.         else {
  222.             switch( ch ) {
  223.                 case  27  : /* Abort Menu */
  224.                     AVL_DEL_WINDOW(w);
  225.                     avl_no_up_corner = 0;
  226.                     AVL_MOUSE_OFF();
  227.                     return 1;
  228.                 case  13  : /* Engage current selection */
  229.                     AVL_DEL_WINDOW(w);
  230.                     ch =  *(avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].sm);
  231.                     if (avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].ret_edit) {
  232.                         ch = 0;
  233.                         AVL_DEL_WINDOW(avl_env_win);
  234.                         AVL_RESTORE_ENV();
  235.                         }
  236.                     avl_smenu[avl_cur_menu].s[avl_cur_smenu[avl_cur_menu]].proc();
  237. /*                    if ((avl_cur_menu == 0) && (avl_cur_smenu[avl_cur_menu] == 3))
  238.                         AVL_BORDER(" GWAda Development Environment ",1,1,3,80,avl_men_bk_color,avl_wnd_color);
  239. */
  240.                     avl_no_up_corner = 0;
  241.                     AVL_MOUSE_OFF();
  242.                     return ch;
  243.                 case 0   : 
  244.                 case 0XE0: {
  245.                     ch = getch();
  246.                     switch(ch)  {
  247.                         case 72 : /* Up  */ 
  248.                             if (avl_cur_smenu[avl_cur_menu] > 0)
  249.                                 --avl_cur_smenu[avl_cur_menu];
  250.                             else
  251.                                 avl_cur_smenu[avl_cur_menu] = rows - 1;
  252.                             break;
  253.                         case 80 : /* Down */ 
  254.                             if (avl_cur_smenu[avl_cur_menu] < (rows - 1))
  255.                                 ++avl_cur_smenu[avl_cur_menu];
  256.                             else
  257.                                 avl_cur_smenu[avl_cur_menu] = 0;
  258.                             break;
  259.                         case 75 : /* Left  */ 
  260.                             if (avl_cur_menu > 0) 
  261.                                 --avl_cur_menu; 
  262.                             else
  263.                                 avl_cur_menu = 8;
  264.                             AVL_DEL_WINDOW(w);
  265.                             w = NULL;
  266.                             AVL_SHOW_MENU();
  267.                             AVL_COMP_SMENU(&rows,&cols);
  268.                             c1 = avl_menu[avl_cur_menu].c - 1;
  269.                             ch = 78 - (c1 + cols);
  270.                             if (ch < 0) c1 += ch;
  271.                             if (!(rows == 0 && cols == 0))
  272.                                 w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
  273.                             _settextcursor(0x2000);
  274.                             break;
  275.                         case 77 : /* Right */ 
  276.                             if (avl_cur_menu < 8) 
  277.                                 ++avl_cur_menu; 
  278.                             else
  279.                                 avl_cur_menu = 0;
  280.                             AVL_DEL_WINDOW(w);
  281.                             w = NULL;
  282.                             AVL_SHOW_MENU();
  283.                             AVL_COMP_SMENU(&rows,&cols);
  284.                             c1 = avl_menu[avl_cur_menu].c - 1;
  285.                             ch = 78 - (c1 + cols);
  286.                             if (ch < 0) c1 += ch;
  287.                             if (!(rows == 0 && cols == 0))
  288.                                 w = AVL_MAKE_WINDOW("",3,c1,rows+4,c1+cols+1,avl_men_bk_color,avl_wnd_color);
  289.                             else
  290.                                 w = NULL;
  291.                             _settextcursor(0x2000);
  292.                             break;